package ru.spb.osll.myfit.server.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ru.spb.osll.myfit.common.Include;
import ru.spb.osll.myfit.common.PageElement;

public class IncludeElementParser implements IPageElementParser {
  private final Pattern INCLUDE_PATTERN = Pattern.compile("!include\\s*(.*)");
  
  @Override
  public boolean matches(String line) {
   return INCLUDE_PATTERN.matcher(line).matches();
  }

  @Override
  public PageElement parse(String line) {
    Matcher matcher = INCLUDE_PATTERN.matcher(line);
    matcher.find();
    String pagePath = matcher.group(1).trim();
    return createInclude(pagePath);
  }
  
  private Include createInclude(String pagePath){
    Include include = new Include();
    include.setPath(pagePath);
    return include;
  }
}
